﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateNew.aspx.cs" Inherits="InformationSystem.WebSite.Module.NoticeMgr.CreateNew" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var fileid = 0;
        function NewFileAdd() {
            //保存Upload实例
            //fileinitload.fileInput.dom.value 完整路径
            //fileinitload - file
            //var g = fileinitload.fileInput.dom;// document.getElementById("fileinitload - file");
            uploadList.show();
            var myfile = document.getElementById('fileinitload-file');

            //TODO 检查文件是否重复全路径匹配

            for (var i = 0; i < hiddenFile.children.length; i++) {
                if (myfile.value == hiddenFile.children[0].value) {
                    Ext.Msg.alert("通知", "此文件已经存在！")
                    //为了不留Bug需要移除此file input ，重新创建


                    var pre = myfile.nextSibling;
                    var ourparent = pre.parentNode;
                    ourparent.removeChild(myfile);
                    var newup = newFileInput();
                    ourparent.insertBefore(newup, pre);
                    return;
                }
            }
            //绘制图形
            var na = new Ext.form.Label;
            na.id = na.id.replace(/-/g, '_')
            var html = "<div style='vertical-align: middle; margin-left: 20px; white-space: nowrap; padding-bottom: 5px; padding-top: 5px'><b style='font-size: 12px'>";
            html = html + myfile.value.substr(myfile.value.lastIndexOf("\\") + 1) + "</b><img style='vertical-align: middle; cursor: pointer; margin-left: 10px' onclick='myremove(\""
            html = html + na.id + "\")'  alt='移除' title='移除' src='../../img/DeleteRed.png' /></div>";
            na.html = html;
            uploadList.add(na);
            uploadList.doLayout();

            myfile.id = na.id + "_hidden";
            hiddenFile.appendChild(myfile);

            var newup = newFileInput();
            //fileinitload.createFileInput();
            //fileinitload.fileInput.id = "fileinitload_file";
            //节点排序
            var pre = document.getElementById('fileinitload').nextSibling;
            var ourparent = pre.parentNode;
            ourparent.insertBefore(newup, pre);

        }

        function newFileInput() {
            var oFileInput = document.createElement('INPUT');
            oFileInput.type = "file";
            oFileInput.id = "fileinitload-file";
            oFileInput.name = "fileinitload-file";
            oFileInput.size = 1;
            oFileInput.className = "x-form-file";
            oFileInput.style.width = "55px";

            oFileInput.attachEvent("onchange", NewFileAdd)
            return oFileInput;
        }

        function callInit() {

            if (document.getElementById('myid').value != '')
                changeUI(document.getElementById('myid').value);
            if (document.getElementById('needresize').value == '1') {
                parent.ResizeFrameHeight(mainPanel.getHeight());
            }
        }
        function changeUI(id) {
            switch (id) {
                case 'cmMail':
                    mainto.show();
                    txtkey.hide();
                    //btnmailSave.show();
                    break;
                case 'cmMsg':
                    mainto.show();
                    txtkey.hide();
                    //btnmailSave.hide();
                    break;
                case 'cmpublicinfo':
                    mainto.hide();
                    txtkey.show();
                    //btnmailSave.hide();
                    break;
                case 'cmworkinfo':
                    mainto.hide();
                    txtkey.hide();
                    //btnmailSave.hide();
                    break;
            }
        }

        function myremove(id) {
            uploadList.remove(id);
            hiddenFile.removeChild(document.getElementById(id + "_hidden"));
            if (hiddenFile.children.length == 0) {
                uploadList.hide();
            }
        }

        function showContact() {
            mywindow.clearContent();
            mywindow.show();
            mywindow.load('Contact.aspx?target=txtto&sto=' + escape(document.getElementById('txtto').value));
        }

        function resetContent() {
           
        }

        function FieldsCheck() {
            if (!mainto.hidden && document.getElementById('txtto').value == '') {
                Ext.Msg.alert('提示', '收件人必须填写!');
                return false;
            }
            if (document.getElementById('txtsubject').value == '') {
                Ext.Msg.alert('提示', '主题必须填写!');
                return false;
            }
            Ext.Msg.wait('正在发送信息，请稍后...', '发送');
            return false;
        }


    </script>
</head>
<body>
    <form id="form1" runat="server" enctype="multipart/form-data">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
        <Listeners>
            <DocumentReady Handler="callInit()" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Viewport runat="server" Layout="FitLayout">
        <Items>
            <ext:Panel ID="mainPanel" runat="server" Header="false" BodyBorder="false" Padding="0" Layout="FitLayout">
                <Items>
                    <ext:Panel runat="server" Title="" Cls="email-form" Frame="true" BodyStyle="10px 5px 5px;"
                        Layout="FitLayout">
                        <TopBar>
                            <ext:Toolbar runat="server">
                                <Items>
                                    <ext:CycleButton ID="btnTypeselect" runat="server" ShowText="true" PrependText="消息类型:"   ToolTip="点击进行消息类型切换">
                                        <Menu>
                                            <ext:Menu runat="server">
                                                <Items>
                                                    <ext:CheckMenuItem ID="cmMail" runat="server" Text="邮件" Icon="Mail" />
                                                    <ext:CheckMenuItem ID="cmMsg" runat="server" Text="消息" Icon="ApplicationOsxAdd" />
                                                    <ext:CheckMenuItem ID="cmpublicinfo" runat="server" Text="公告" Icon="Add" />
                                                    <ext:CheckMenuItem ID="cmworkinfo" runat="server" Text="就业信息" Icon="User" />
                                                </Items>
                                            </ext:Menu>
                                        </Menu>
                                        <Listeners>
                                            <Change Handler="changeUI(#{btnTypeselect}.activeItem.id)" />
                                        </Listeners>
                                    </ext:CycleButton>
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server">
                                    </ext:ToolbarFill>
                                    <ext:Button runat="server" Text="发送" Icon="EmailGo">
                                        <Listeners>
                                            <Click Handler="if (!mainto.hidden && document.getElementById('txtto').value == '') {
                                                                    Ext.Msg.alert('提示', '收件人必须填写!');
                                                                    return false;
                                                                }
                                                                if (document.getElementById('txtsubject').value == '') {
                                                                    Ext.Msg.alert('提示', '主题必须填写!');
                                                                    return false;
                                                                }
                                                                Ext.Msg.wait('正在发送信息，请稍后...', '发送');
                                                                return true;" />
                                        </Listeners>
                                        <DirectEvents>
                                            <Click OnEvent="btnSend_Click">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                    <ext:Button runat="server" ID="btnmailSave" Text="保存" Icon="Disk" Hidden="true">
                                        <DirectEvents>
                                            <%--  <Click OnEvent="btnSave_Click" Before="Ext.Msg.wait('正在保存信息，请稍后...', '保存');">
                                            </Click>--%>
                                        </DirectEvents>
                                    </ext:Button>
                                    <%--<ext:Button runat="server" Text="打印" Icon="Printer">
                                    </ext:Button>--%>
                                    <ext:FileUploadField runat="server" ID="fileinitload" ButtonOnly="true" ButtonText="附件"
                                        Icon="PageAttach">
                                        <Listeners>
                                            <FileSelected Handler="NewFileAdd()" />
                                        </Listeners>
                                    </ext:FileUploadField>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:FormPanel runat="server" BaseCls="x-plain" Border="true" Padding="5" LabelWidth="80">
                                <Items>
                                    <ext:CompositeField runat="server" ID="mainto" AnchorHorizontal="100%">
                                        <Items>
                                            <ext:TextField ID="txtto" FieldLabel="接收者" runat="server" AnchorHorizontal="100%"
                                                Flex="1" Height="22" />
                                            <ext:Button ID="Button1" runat="server" Text="联系人...">
                                                <Listeners>
                                                    <Click Handler="showContact()" />
                                                </Listeners>
                                            </ext:Button>
                                        </Items>
                                    </ext:CompositeField>
                                    <ext:TextField ID="txtsubject" FieldLabel="主题" runat="server" AnchorHorizontal="100%" />
                                    <ext:TextField ID="txtkey" FieldLabel="关键字" runat="server" AnchorHorizontal="100%" />
                                    <ext:FieldSet runat="server" ID="uploadList" Layout="TableLayout" FieldLabel="附件"
                                        AutoScroll="true" Height="50" Hidden="true">
                                        <%-- <Items>
                                            <ext:Label ID="Label1" runat="server">
                                                <Content>
                                                    <div style="vertical-align: middle; margin-left: 20px; white-space: nowrap; padding-bottom: 5px;
                                                        padding-top: 5px">
                                                        <b style="font-size: 12px">附件1.xls</b><img style="vertical-align: middle; cursor: pointer;
                                                            margin-left: 10px" alt="移除" title="移除" src="../../img/DeleteRed.png" onclick="myremove(Label1)" /></div>
                                                </Content>
                                            </ext:Label>
                                            <ext:Label ID="Label2" runat="server" Html="">
                                            </ext:Label>
                                        </Items>--%>
                                    </ext:FieldSet>
                                    <ext:HtmlEditor ID="txtContent" runat="server" HideLabel="true" AnchorHorizontal="100%" AnchorVertical="75%" EnableLists="false">
                                    </ext:HtmlEditor>
                                </Items>
                            </ext:FormPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    <input type="hidden" name="myid" runat="server" id="myid" value='' />
    <input type="hidden" name="needresize" id="needresize" runat="server" value='' />
    <div id="hiddenFile" style="display: none">
   
    </div>
    <ext:Window runat="server" ID="mywindow" Width="600" Height="440" Hidden="true" Layout="FitLayout"
        Modal="true">
        <AutoLoad ShowMask="true" Mode="IFrame" MaskMsg="正在加载页面，请稍后...">
        </AutoLoad>
    </ext:Window>
    </form>
</body>
</html>
